﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HanGu.Services.Interface;
using HanGu.Entity;

namespace HanGu.Services
{
    public class AdvertisementService : BaseService, IAdvertisement
    {

        public List<Advertisement> GetAll()
        {
            using (HaiGuEntities obj = new HaiGuEntities())
            {
                return obj.Advertisement.OrderBy(c => c.Order).ToList();
            }
        }

        public List<Advertisement> GetAll(UniversallySearchParam searchparma)
        {
            using (HaiGuEntities obj = new HaiGuEntities())
            {
                List<Advertisement> list = new List<Advertisement>();
                if (searchparma.IntObj1 == 0)
                {
                    list = obj.Advertisement.OrderBy(c => c.Order).ToList();
                }
                else
                {
                    list = obj.Advertisement.Where(c=>c.ClassType==searchparma.IntObj1).OrderBy(c => c.Order).ToList();
                }
                return list;
            }
        }

        public Advertisement GetByID(int id)
        {
            using (HaiGuEntities obj = new HaiGuEntities())
            {
                return obj.Advertisement.Where(c => c.ID == id).FirstOrDefault();
            }
        }


        public bool Add(Advertisement model)
        {
            try
            {
                this.Add<Advertisement>(model);
                return true;
            }
            catch { return false; }
        }

        public bool Update(Advertisement model)
        {
            try
            {
                this.Update<Advertisement>(model);
                return true;
            }
            catch { return false; }
        }

        public bool Delete(int id)
        {
            try
            {
                this.Delete<Advertisement>(c => c.ID == id);
                return true;
            }
            catch { return false; }
        }

        
    }
}
